package com.orphan.audit.controller;


import com.orphan.audit.po.GoodsInfo;
import com.orphan.audit.po.SupplierCheck;
import com.orphan.audit.po.SupplierInfo;
import com.orphan.audit.service.IGoodsInfoService;
import com.orphan.audit.service.ISupplierCheckService;
import com.orphan.audit.service.ISupplierInfoService;
import com.orphan.util.dto.SettlementSupplierDto;
import com.orphan.util.dto.SettlementSupplierGoodsDto;
import com.orphan.util.mqConfig.MQUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wdn
 * @since 2021-07-16
 */
@RestController
@RequestMapping("/supplier-check")
public class SupplierCheckController {

    @Autowired
    ISupplierCheckService supplierCheckService;
    @Autowired
    ISupplierInfoService supplierInfoService;
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/findAll")
    @ResponseBody
    public List<SupplierCheck> test(){
        return supplierCheckService.findAll();
    }

    @GetMapping("addOrder")
    public String addOrder(){
        List<SupplierInfo> goodsList = supplierInfoService.findAll();
        List<SettlementSupplierGoodsDto> settlementList = new ArrayList<>();
        SettlementSupplierDto dto = new SettlementSupplierDto();
        SettlementSupplierGoodsDto goodsDto = new SettlementSupplierGoodsDto();
        for (int i = 0; i < goodsList.size(); i++) {
            dto.setOrderNum(goodsList.get(i).getSupplierCheck().getTNum());
            dto.setPlanId(goodsList.get(i).getSupplierCheck().getTPlanid());
            dto.setSupplierName(goodsList.get(i).getSupplierCheck().getTSuppliername());
            dto.setTotalMoney(goodsList.get(i).getSupplierCheck().getTTotal());
            //供应商品集合
            goodsDto.setGoodsId(goodsList.get(i).getTId());
            goodsDto.setGoodsName(goodsList.get(i).getTGoodsname());
            goodsDto.setGoodsNum(goodsList.get(i).getTGoodsnum());
            goodsDto.setSize(goodsList.get(i).getTSize());
            goodsDto.setType(goodsList.get(i).getTGoodstype());
            goodsDto.setPrice(goodsList.get(i).getTPrice());
            settlementList.add(goodsDto);
            //商品集合放入dto中
            dto.setSupplierGoods(settlementList);
//            mqUtil.send("directExchange1","one",dto);
            rabbitTemplate.convertAndSend("directExchange1","one",dto);
        }
        return "好了哦";
    }

//    @GetMapping("test1")
//    public String test1(){
//        String str = "傻逼";
//        rabbitTemplate.convertAndSend("directExchange1","one",str);
//        return "ok";
//    }

//    @RequestMapping("/getOrder")
//    @RabbitListener(queues = "queue1")
//    public void getOrder(SettlementSupplierDto dto){
//        System.out.println("取出来了:"+ dto);
//
//    }

}
